<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_wallet_log', function (Blueprint $table) {
            $table->id();
            $table->integer('user_id')->default(0)->comment('用户ID');
            $table->enum('type',['money','score'])->default('money')->comment('钱包类型:money=余额,score=积分');
            $table->decimal('value',10,2)->default(0.00)->comment('变动值');
            $table->decimal('before',10,2)->default(0.00)->comment('变更前');
            $table->decimal('after',10,2)->default(0.00)->comment('变更后');
            $table->string('remark',255)->default('')->comment('说明');
            $table->integer('log_type')->default(0)->comment('日志类型');
            $table->integer('table_id')->default(0)->comment('来源表ID');
            $table->string('table_name')->default('')->comment('来源表Name');
            $table->integer('created_at')->default(0)->comment('创建时间');
        });
        DB::statement("ALTER TABLE `user_wallet_log` comment '【用户】钱包流水'");
        $list_id = DB::table('admin_menus')->insertGetId([
            'name'        => '用户钱包流水',
            'path'        => 'arts/manage/user_wallet_log',
            'icon'        => 'el-icon-s-order',
            'module_type' => 'extend',
            'level'       => 2,
            'facility'    => 1,
            'sort'        => 255,
            'status'      => 1,
            'created_at'  => time()
        ]);
        DB::table('admin_menus')->insert([
            [
                'parent_id'   => $list_id,
                'name'        => '删除',
                'path'        => 'arts/manage/user/remove',
                'action'      => 'remove',
                'icon'        => 'el-icon-delete',
                'level'       => 3,
                'facility'    => 2,
                'sort'        => 255,
                'status'      => 1,
                'created_at'  => time()
            ]
        ]);
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_wallet_log');
    }
};
